package com.mcp.mcpserver.repository;

import com.mcp.mcpserver.model.DataSourceModel;
import org.springframework.stereotype.Repository;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
/**
 * @author zhangxin569
 * @date 2025/8/6
 */
@Repository
public class InMemoryDataSourceRepository {
    private final Map<String, DataSourceModel> dataSources = new ConcurrentHashMap<>();

    public void save(DataSourceModel config) {
        dataSources.put(config.getName(), config);
    }

    public Optional<DataSourceModel> findByName(String name) {
        return Optional.ofNullable(dataSources.get(name));
    }

    public List<DataSourceModel> findAll() {
        return new ArrayList<>(dataSources.values());
    }

    public boolean existsByName(String name) {
        return dataSources.containsKey(name);
    }

    public void deleteByName(String name) {
        dataSources.remove(name);
    }
}